package ema.tpjee.banking.session;

import java.io.Serializable;
import java.util.List;

import ema.tpjee.banking.controler.BankControler;
import ema.tpjee.banking.controler.CustomerControler;
import ema.tpjee.banking.controler.StartControler;
import ema.tpjee.banking.model.Bank;
import ema.tpjee.banking.model.Customer;


public class Session implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4885962577769819842L;

	private BankControler bankControler;
	private CustomerControler customerControler;

	private Customer currentCustomer;
	private Bank currentBank;

	private StartControler startControler;

	public Session() {
		super();
		System.out.println("creating Session");
		bankControler = new BankControler();
		bankControler.setSession(this);
		customerControler = new CustomerControler();
		customerControler.setSession(this);
		startControler = new StartControler();
		startControler.setSession(this);
		System.out.println("");
		if (bankControler.getBanks().size()==0){
		  System.out.println("populating");
		  List<Bank> bks=bankControler.getBankDao().populate();
		  setCurrentBank(bks.get(0));
		  List<Customer> cts=customerControler.getCustomerDao().populate(bks.get(0));
		  setCurrentCustomer(cts.get(0));
		} else{
			 System.out.println("already populated");
			 setCurrentBank(bankControler.getBanks().get(0));
			 setCurrentCustomer(getCurrentBank().getCustomers().get(0));
		}
	}

	public BankControler getBankControler() {
		System.out.println("getting BankControler");
		return bankControler;
	}

	public void setBankControler(BankControler bankControler) {
	
	}

	public CustomerControler getCustomerControler() {
		System.out.println("getting CustomerControler");
		return customerControler;
	}

	public void setCustomerControler(CustomerControler customerControler) {

	}

	public void setCurrentBank(Bank b) {
		currentBank = b;
	}

	public Bank getCurrentBank() {
		return currentBank;
	}

	public void setCurrentCustomer(Customer c) {
		if (c != null)
			System.out.println("Session.setCurrentCustomer: " + c.toString());
		else
			System.out.println("Session.setCurrentCustomer: null");
		this.currentCustomer = c;
	}

	public Customer getCurrentCustomer() {

		return currentCustomer;
	}

	public ema.tpjee.banking.controler.StartControler getStartControler() {
		return startControler;
	}

	public void setStartControler(
			ema.tpjee.banking.controler.StartControler startControler) {

	}

}
